﻿//报表模板文件 'D:\java\eclipse\bpm_new\Printing_test\WebContent\grf\OnlyDetail.grf' 对应的程序定义代码
var gridreport = gridreport || {};

(function (undefined) {
    "use strict";

    //报表模板定义类，调用其 createReport 成员函数生成报表模板定义
    gridreport.OnlyDetail = {};

    gridreport.OnlyDetail.createReport = function (report) {
        //定义报表主队象
        var defineReportMain = function(report) {
            var infoListParameter,
                infoParameter,
                newParameter;

            report.Title = "Grid++Report";
            report.PageDivideLine = true;
            report.PrintAsDesignPaper = false;

            report.Font.Name = "宋体";
            report.Font.Point = 9;
            report.Font.Weight = 400;
            report.Font.Charset = 134;

            report.Printer.DesignTopMargin = 1.5;
            report.Printer.DesignBottomMargin = 1.5;

            //定义报表参数集合
            {
                infoListParameter = [];

                infoParameter = {};
                infoListParameter.push(infoParameter);
                infoParameter.Name = "Comment";
                infoParameter.Tag = "";
                infoParameter.DataType = 1;
                infoParameter.Format = "";
                infoParameter.Value = "演示一个最基本的列表报表。";
                infoListParameter.forEach(function (item) {
                    //IGridppReport.AddParameter  方法也可以用来新增报表参数定义
                    newParameter = report.Parameters.Add();

                    newParameter.Name = item.Name;
                    newParameter.Tag = item.Tag;
                    newParameter.DataType = item.DataType;
                    newParameter.Format = item.Format;
                    newParameter.Value = item.Value;
                });
            }
        };

        //定义页眉
        var definePageHeader = function(report) {
            var pageheader,
                controls,
                MemoBox,
                Line;

            pageheader = report.InsertPageHeader();

            pageheader.Height = 1.32292;

            //定义 '页眉' 的各个部件框(Control)
            {
                controls = pageheader.Controls;

                //定义部件框 'MemoBox1'
                {
                    MemoBox = controls.Add(8).AsMemoBox;
                    MemoBox.Name = "MemoBox1";
                    MemoBox.Anchor = 6;
                    MemoBox.Left = 2.19604;
                    MemoBox.Top = 0.396875;
                    MemoBox.Width = 13.7054;
                    MemoBox.Height = 0.47625;

                    MemoBox.Font.Name = "楷体";
                    MemoBox.Font.Point = 12;
                    MemoBox.Font.Bold = true;
                    MemoBox.Font.Charset = 134;

                    MemoBox.Text = "欢迎访问Grid++Report网站www.rubylong.cn，了解最新产品信息。";
                }

                //定义部件框 'Line1'
                {
                    Line = controls.Add(10).AsLine;
                    Line.Name = "Line1";
                    Line.Anchor = 7;
                    Line.Top = 1.00542;
                    Line.Width = 16.0073;

                    Line.LinePen.Width = 2;
                    Line.X1 = 0;
                    Line.X2 = 16.0073;
                    Line.Y1 = 1.00542;
                    Line.Y2 = 1.00542;
                }
            }
        };

        //定义页脚
        var definePageFooter = function(report) {
            var pagefooter,
                controls,
                MemoBox;

            pagefooter = report.InsertPageFooter();

            pagefooter.Height = 1.32292;

            //定义 '页脚' 的各个部件框(Control)
            {
                controls = pagefooter.Controls;

                //定义部件框 'MemoBox2'
                {
                    MemoBox = controls.Add(8).AsMemoBox;
                    MemoBox.Name = "MemoBox2";
                    MemoBox.Anchor = 6;
                    MemoBox.Left = 13.2027;
                    MemoBox.Top = 0.396875;
                    MemoBox.Width = 2.59292;
                    MemoBox.Height = 0.608542;

                    MemoBox.Text = "第[#SystemVar(PageNumber)#]页 共[#SystemVar(PageCount)#]页";
                }

                //定义部件框 'MemoBox3'
                {
                    MemoBox = controls.Add(8).AsMemoBox;
                    MemoBox.Name = "MemoBox3";
                    MemoBox.Left = 0.211667;
                    MemoBox.Top = 0.396875;
                    MemoBox.Width = 6.19125;
                    MemoBox.Height = 0.608542;

                    MemoBox.Text = "打印时间：[#SystemVar(CurrentDateTime):yyyy年MM月dd日 HH:mm:ss#]";
                }
            }
        };

        //定义各个报表头
        var defineReportHeaders = function(report) {
            var reportheaders,
                reportheader,
                controls,
                StaticBox;

            reportheaders = report.ReportHeaders;

            //定义报表头 ''
            {
                reportheader = reportheaders.Add();

                reportheader.Height = 0.978958;

                //定义 '(报表头)' 的各个部件框(Control)
                {
                    controls = reportheader.Controls;

                    //定义部件框 'StaticBox1'
                    {
                        StaticBox = controls.Add(1).AsStaticBox;
                        StaticBox.Name = "StaticBox1";
                        StaticBox.Center = 1;
                        StaticBox.Left = 7.54063;
                        StaticBox.Top = 0.185208;
                        StaticBox.Width = 3.41313;
                        StaticBox.Height = 0.582083;

                        StaticBox.Font.Name = "宋体";
                        StaticBox.Font.Point = 15;
                        StaticBox.Font.Bold = true;
                        StaticBox.Font.Charset = 134;

                        StaticBox.Text = "客户基本信息";
                    }
                }
            }
        };

        //定义明细网格
        var defineDetailGrid = function(report) {
            var detailgrid,
                recordset,
                infoListField,
                infoField,
                newField;

            detailgrid = report.InsertDetailGrid();
            recordset = detailgrid.Recordset;
            detailgrid.CenterView = true;
            detailgrid.PrintAdaptMethod = 3;

            recordset.ConnectionString = "XML";
            recordset.QuerySQL = "OnlyDetail.txt";

            //定义字段集合
            {
                infoListField = [];

                infoField = {};
                infoListField.push(infoField);
                infoField.Name = "CustomerID";
                infoField.Tag = "";
                infoField.FieldType = 1;
                infoField.Format = "";
                infoField.GetDisplayTextScript = "";
                infoField.Length = 0;
                infoField.RTrimBlankChars = false;
                infoField.DBFieldName = "CustomerID";

                infoField = {};
                infoListField.push(infoField);
                infoField.Name = "CompanyName";
                infoField.Tag = "";
                infoField.FieldType = 1;
                infoField.Format = "";
                infoField.GetDisplayTextScript = "";
                infoField.Length = 0;
                infoField.RTrimBlankChars = false;
                infoField.DBFieldName = "CompanyName";

                infoField = {};
                infoListField.push(infoField);
                infoField.Name = "ContactName";
                infoField.Tag = "";
                infoField.FieldType = 1;
                infoField.Format = "";
                infoField.GetDisplayTextScript = "";
                infoField.Length = 0;
                infoField.RTrimBlankChars = false;
                infoField.DBFieldName = "ContactName";

                infoField = {};
                infoListField.push(infoField);
                infoField.Name = "Address";
                infoField.Tag = "";
                infoField.FieldType = 1;
                infoField.Format = "";
                infoField.GetDisplayTextScript = "";
                infoField.Length = 0;
                infoField.RTrimBlankChars = false;
                infoField.DBFieldName = "Address";

                infoField = {};
                infoListField.push(infoField);
                infoField.Name = "City";
                infoField.Tag = "";
                infoField.FieldType = 1;
                infoField.Format = "";
                infoField.GetDisplayTextScript = "";
                infoField.Length = 0;
                infoField.RTrimBlankChars = false;
                infoField.DBFieldName = "City";

                infoField = {};
                infoListField.push(infoField);
                infoField.Name = "Region";
                infoField.Tag = "";
                infoField.FieldType = 1;
                infoField.Format = "";
                infoField.GetDisplayTextScript = "";
                infoField.Length = 0;
                infoField.RTrimBlankChars = false;
                infoField.DBFieldName = "Region";

                infoField = {};
                infoListField.push(infoField);
                infoField.Name = "PostalCode";
                infoField.Tag = "";
                infoField.FieldType = 1;
                infoField.Format = "";
                infoField.GetDisplayTextScript = "";
                infoField.Length = 0;
                infoField.RTrimBlankChars = false;
                infoField.DBFieldName = "PostalCode";

                infoField = {};
                infoListField.push(infoField);
                infoField.Name = "Phone";
                infoField.Tag = "";
                infoField.FieldType = 1;
                infoField.Format = "";
                infoField.GetDisplayTextScript = "";
                infoField.Length = 0;
                infoField.RTrimBlankChars = false;
                infoField.DBFieldName = "Phone";
                infoListField.forEach(function (item) {
                    //IGRRecordset.AddField 方法也可以用来新增字段定义
                    newField = recordset.Fields.Add();

                    newField.Name = item.Name;
                    newField.Tag = item.Tag;
                    newField.FieldType = item.FieldType;
                    newField.Format = item.Format;
                    newField.GetDisplayTextScript = item.GetDisplayTextScript;
                    newField.Length = item.Length;
                    newField.RTrimBlankChars = item.RTrimBlankChars;
                    newField.DBFieldName = item.DBFieldName;
                });
            }

            defineDetailGridLayout(detailgrid);
        };

        //定义明细网格的布局(列、标题格、内容格、多层表头)
        var defineDetailGridLayout = function(detailgrid) {
            var columnTitle,
                columnContent,
                column,
                titleCell,
                contentCell;

            //定义标题行
            {
                columnTitle = detailgrid.ColumnTitle;

                columnTitle.BackColor = 192 * 256 * 256 + 192 * 256 + 192;
                columnTitle.Height = 0.79375;

                columnTitle.Font.Name = "宋体";
                columnTitle.Font.Point = 9;
                columnTitle.Font.Bold = true;
                columnTitle.Font.Charset = 134;
                columnTitle.RepeatStyle = 2;
            }

            //定义内容行
            {
                columnContent = detailgrid.ColumnContent;

                columnContent.Height = 0.79375;
            }

            //定义列 'CustomerID'
            {
                column = detailgrid.Columns.Add();
                column.Name = "CustomerID";
                column.Width = 2.38125;

                titleCell = column.TitleCell;
                titleCell.Text = "客户编号";
                titleCell.BackColor = 255 * 256 * 256 + 255 * 256 + 255;

                contentCell = column.ContentCell;
                contentCell.DataField = "CustomerID";

            }

            //定义列 'CompanyName'
            {
                column = detailgrid.Columns.Add();
                column.Name = "CompanyName";
                column.Width = 3.175;

                titleCell = column.TitleCell;
                titleCell.Text = "公司名称";
                titleCell.BackColor = 255 * 256 * 256 + 255 * 256 + 255;

                contentCell = column.ContentCell;
                contentCell.DataField = "CompanyName";

            }

            //定义列 'ContactName'
            {
                column = detailgrid.Columns.Add();
                column.Name = "ContactName";
                column.Width = 1.5875;

                titleCell = column.TitleCell;
                titleCell.Text = "联系人";
                titleCell.BackColor = 255 * 256 * 256 + 255 * 256 + 255;

                contentCell = column.ContentCell;
                contentCell.DataField = "ContactName";

            }

            //定义列 'Address'
            {
                column = detailgrid.Columns.Add();
                column.Name = "Address";
                column.Width = 3.175;

                titleCell = column.TitleCell;
                titleCell.Text = "地址";
                titleCell.BackColor = 255 * 256 * 256 + 255 * 256 + 255;

                contentCell = column.ContentCell;
                contentCell.DataField = "Address";

            }

            //定义列 'City'
            {
                column = detailgrid.Columns.Add();
                column.Name = "City";
                column.Width = 1.5875;

                titleCell = column.TitleCell;
                titleCell.Text = "城市";
                titleCell.BackColor = 255 * 256 * 256 + 255 * 256 + 255;

                contentCell = column.ContentCell;
                contentCell.DataField = "City";

            }

            //定义列 'Region'
            {
                column = detailgrid.Columns.Add();
                column.Name = "Region";
                column.Width = 1.98438;

                titleCell = column.TitleCell;
                titleCell.Text = "地区";
                titleCell.BackColor = 255 * 256 * 256 + 255 * 256 + 255;

                contentCell = column.ContentCell;
                contentCell.DataField = "Region";

            }

            //定义列 'PostalCode'
            {
                column = detailgrid.Columns.Add();
                column.Name = "PostalCode";
                column.Width = 1.5875;

                titleCell = column.TitleCell;
                titleCell.Text = "邮编";
                titleCell.BackColor = 255 * 256 * 256 + 255 * 256 + 255;

                contentCell = column.ContentCell;
                contentCell.DataField = "PostalCode";

            }

            //定义列 'Phone'
            {
                column = detailgrid.Columns.Add();
                column.Name = "Phone";
                column.Width = 2.98979;

                titleCell = column.TitleCell;
                titleCell.Text = "电话";
                titleCell.BackColor = 255 * 256 * 256 + 255 * 256 + 255;

                contentCell = column.ContentCell;
                contentCell.DataField = "Phone";

            }
        };

        //通过程序代码定义报表模板的主函数，调用此函数创建报表模板

        //定义报表主对象
        defineReportMain(report);

        //定义页眉
        definePageHeader(report);

        //定义页脚
        definePageFooter(report);

        //定义报表头
        defineReportHeaders(report);

        //定义明细网格
        defineDetailGrid(report);
    };
})();
